package kd.xkqj.unittest.plugin.setting;


import com.intellij.openapi.components.PersistentStateComponent;
import com.intellij.openapi.components.State;
import com.intellij.openapi.components.Storage;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

/**
 * @description: 插件设置服务
 * @author feng_jun_peng
 * @create 2024-12-18 09:18
 * @version 1.0
 */
@State(
        name = "kd.xkqj.unittest.plugin.setting.PluginSettingsUI",
        storages = @Storage("PluginSettings.xml") // 存储文件路径
)
public class PluginSettingsService implements PersistentStateComponent<PluginSettingsService.State> {

    private State state = new State();

    public static class State {
        public boolean showConfirm = true; //每次创建或更新时，弹窗确认
        public boolean genPublic = true; //生成公共方法
        public boolean genProtected = false; //生成保护方法
        public boolean genPrivate = false; //生成私有方法
        public boolean addUnsupportedEx = false; //新增方式时，加入 UnsupportedOperationException 未实现异常
        public boolean autoExtendPlugin = false; // 若类继承插件，则创建时自动继承AbstractJUnitTestPlugIn
        public boolean addDisplayName = true; //自动添加DisplayName注解
        public boolean addNOClientMock = true; //自动添加NOClientMock注解
        public boolean addCustomParams = true; //自动添加CustomParams注解
        public boolean autoGenJWYTest = false; // 创建时，自动添加init、release方法，并自动引用core包（PLM 贾武阳）
        public String importPackages = "" +
                "import java.util.*;\n" +
                "import org.junit.After;\n" +
                "import org.junit.Before;\n" +
                "import org.junit.Test;\n" +
                "import org.junit.Assert;\n" +
                "import kd.bos.dataentity.entity.DynamicObject;\n" +
                "import kd.bos.form.unittest.*;\n" +
                "import kd.bos.unittest.*;\n" +
                "import kd.bos.test.*;\n" +
                "import static org.mockito.ArgumentMatchers.any;\n" +
                "import static org.mockito.Mockito.*;\n" ; //新增方法时，默认依赖的包
    }

    @Nullable
    @Override
    public State getState() {
        return state;
    }

    @Override
    public void loadState(@NotNull State state) {
        this.state = state;
    }

    public static PluginSettingsService getInstance() {
        return com.intellij.openapi.application.ApplicationManager.getApplication().getService(PluginSettingsService.class);
    }
}

